﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using V5_Model;
using V5_DAL.SqlServer;

namespace V5_EShop._Class.BLL
{
    public class BLLGZCustomOutPrice
    {
        private readonly DALGZCustomOutPrice dal = new DALGZCustomOutPrice();

        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(Guid CustomID, Guid ProductID)
        {
            return dal.Exists(CustomID, ProductID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public void Add(ModelGZCustomOutPrice model)
        {
            dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(ModelGZCustomOutPrice model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(Guid CustomID, Guid ProductID)
        {

            return dal.Delete(CustomID, ProductID);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public ModelGZCustomOutPrice GetModel(Guid CustomID, Guid ProductID)
        {

            return dal.GetModel(CustomID, ProductID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ModelGZCustomOutPrice> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<ModelGZCustomOutPrice> DataTableToList(DataTable dt)
        {
            List<ModelGZCustomOutPrice> modelList = new List<ModelGZCustomOutPrice>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                ModelGZCustomOutPrice model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new ModelGZCustomOutPrice();
                    if (dt.Rows[n]["ID"] != null && dt.Rows[n]["ID"].ToString() != "")
                    {
                        model.ID = new Guid(dt.Rows[n]["ID"].ToString());
                    }
                    if (dt.Rows[n]["CustomID"] != null && dt.Rows[n]["CustomID"].ToString() != "")
                    {
                        model.CustomID = new Guid(dt.Rows[n]["CustomID"].ToString());
                    }
                    if (dt.Rows[n]["ProductID"] != null && dt.Rows[n]["ProductID"].ToString() != "")
                    {
                        model.ProductID = new Guid(dt.Rows[n]["ProductID"].ToString());
                    }
                    if (dt.Rows[n]["OutBulkPrice"] != null && dt.Rows[n]["OutBulkPrice"].ToString() != "")
                    {
                        model.OutBulkPrice = decimal.Parse(dt.Rows[n]["OutBulkPrice"].ToString());
                    }
                    if (dt.Rows[n]["OutPiecePrice"] != null && dt.Rows[n]["OutPiecePrice"].ToString() != "")
                    {
                        model.OutPiecePrice = decimal.Parse(dt.Rows[n]["OutPiecePrice"].ToString());
                    }
                    if (dt.Rows[n]["LastOutBulkPrice"] != null && dt.Rows[n]["LastOutBulkPrice"].ToString() != "")
                    {
                        model.LastOutBulkPrice = decimal.Parse(dt.Rows[n]["LastOutBulkPrice"].ToString());
                    }
                    if (dt.Rows[n]["LastOutPicePrice"] != null && dt.Rows[n]["LastOutPicePrice"].ToString() != "")
                    {
                        model.LastOutPicePrice = decimal.Parse(dt.Rows[n]["LastOutPicePrice"].ToString());
                    }
                    if (dt.Rows[n]["PromotionsStartDate"] != null && dt.Rows[n]["PromotionsStartDate"].ToString() != "")
                    {
                        model.PromotionsStartDate = DateTime.Parse(dt.Rows[n]["PromotionsStartDate"].ToString());
                    }
                    if (dt.Rows[n]["PromotionsEndDate"] != null && dt.Rows[n]["PromotionsEndDate"].ToString() != "")
                    {
                        model.PromotionsEndDate = DateTime.Parse(dt.Rows[n]["PromotionsEndDate"].ToString());
                    }
                    if (dt.Rows[n]["PromotionsPrice"] != null && dt.Rows[n]["PromotionsPrice"].ToString() != "")
                    {
                        model.PromotionsPrice = decimal.Parse(dt.Rows[n]["PromotionsPrice"].ToString());
                    }
                    if (dt.Rows[n]["TimeStamp"] != null && dt.Rows[n]["TimeStamp"].ToString() != "")
                    {
                        model.TimeStamp = DateTime.Parse(dt.Rows[n]["TimeStamp"].ToString());
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}